-- box
-- created by panyl
-- 地牢格子：宝箱

return {
    restoreGrid = function(grid, info)
        -- 箱子奖励
        local bonus = info.bonus;
        if bonus.array then
            grid.bonus = bonus:toTable();
        else
            grid.bonus = bonus;
        end

        local monster = grid.monster;

        -- 如果怪物没死亡
        if 1 ~= info.is_dead then
            if info.class_id then
                monster.classId = info.class_id;

                local dbase = {
                    ["class_id"] = info.class_id,
                    ["skills"]   = MonsterM.query(info.class_id, "skills"),
                };

                monster.dbase:aborb(dbase);
            end

            -- 还原
            monster:restoreInfo(info);

            -- 闪避
            monster.dbase:set("dodge", info.dodge);

            -- rank
            monster.dbase:set("rank", info.rank or 0);
        else
            -- 死亡了
            monster.dbase:set("is_dead", 1);
        end
    end,

    -- 收集上下文
    collectContext = function(grid)
        -- 如果箱子已经被拾取过了
        if not grid.bonus then
            return {};
        end

        local ret = {};
        local monster = grid.monster;

        -- 怪物没死亡
        if not monster:isDead() then
            -- 收集信息
            ret = monster:collectInfo();

            ret.dodge  = monster.dbase:query("dodge", 0);
        else
            ret.is_dead = 1;
        end


        ret.rank = monster:getRank() or 0;
        ret.bonus = grid.bonus;
        -- ret.state = GRID_STATE_OPEN;

        return ret;
    end
};
